
package sharedServlets;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import sessionMenegment.SessionMgr;
import validate.Validate;

import com.google.appengine.api.datastore.Email;
import com.google.appengine.api.datastore.PhoneNumber;

import controller.Controller;


@SuppressWarnings("serial")
public class GmailLoginPhone extends HttpServlet {
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
	throws IOException {
		
		HttpSession session = req.getSession();
		String phone = req.getParameter("phoneNumber");
		String userName = (String) session.getAttribute("userNameClient");
		String userEmail = (String) session.getAttribute("userEmail");
		System.out.println("Email: "+userEmail);
		System.out.println("userName: "+userName);
		if(Validate.phoneValid(phone)){
			Controller.getInstance().newClientAccount(userName, "", new PhoneNumber(phone), new Email(userEmail));
			SessionMgr.getInst().registerUser(req.getSession(), userName,"client");
			resp.sendRedirect("allClientOrders.jsp");
			
		}
		else{
			session.setAttribute("error", "Invalid phone number.");
			resp.sendRedirect("gmailLogin");
		}
		
		
		
		
		
	}
	
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
	throws IOException {
	}
}
	
